//
//  ESTCarBrandSeriesConfigSectionHeaderView.m
//  ESTSCRMAPP
//
//  Created by 李贤立 on 2018/10/23.
//  Copyright © 2018年 Capfer. All rights reserved.
//

#import "ESTCarBrandSeriesConfigSectionHeaderView.h"

@interface ESTCarBrandSeriesConfigSectionHeaderView ()
/**
 *  左边按钮
 */
@property(nonatomic, strong) TYZButton *leftButton;
/**
 *  右边数值
 */
@property(nonatomic, strong) TYZLabel *rightLabel;
@end

@implementation ESTCarBrandSeriesConfigSectionHeaderView

/**
 创建组头

 @param tableView tableView
 @return 快速创建组头
 */
+ (instancetype)creatCarBrandSeriesConfigSectionHeaderView:(UITableView *)tableView {
    ESTCarBrandSeriesConfigSectionHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"ESTCarBrandSeriesConfigSectionHeaderView"];
    if (headerView == nil) {
        headerView = [[ESTCarBrandSeriesConfigSectionHeaderView alloc] initWithReuseIdentifier:@"ESTCarBrandSeriesConfigSectionHeaderView"];
    }
    return headerView;
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        TYZButton *leftButton = [TYZButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:leftButton];
        [leftButton setTitleColor:TYZBlackColor forState:UIControlStateNormal];
        leftButton.titleLabel.font = [UIFont boldSystemFontOfSize:CoreInfo.fontSize];
        [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.centerY.equalTo(self);
        }];
        self.leftButton = leftButton;
        
        TYZLabel *rightLabel = [[TYZLabel alloc] init];
        [self addSubview:rightLabel];
        [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-20);
        }];
        rightLabel.font = TYZFont(CoreInfo.fontSize * 0.8);
        rightLabel.textColor = TYZLightMColor;
        rightLabel.textAlignment = NSTextAlignmentRight;
        self.rightLabel = rightLabel;
        
        TYZButton *coverButton = [TYZButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:coverButton];
        [coverButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        [coverButton addTarget:self action:@selector(didClickCoverButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (void)didClickCoverButton {
    if (self.didClickCoverBlock) {
        self.didClickCoverBlock();
    }
}
- (void)setLeftTitle:(NSString *)leftTitle {
    _leftTitle = leftTitle;
    [self.leftButton setTitle:leftTitle forState:UIControlStateNormal];
}
- (void)setRightValue:(NSInteger)rightValue {
    _rightValue = rightValue;
    self.rightLabel.text = [NSString stringWithFormat:@"%ld", (long)rightValue];
}
@end
